var ns, app;
app = new Vue({
    el: '#app',
    data: {
        list:[],
        type:1,
    },
    methods: {
        guanbi_pic:function(id){
            var that=this;
            that.list = that.list.filter((item) => {
                return item.UserID != id
                });
            api.sendEvent({
                name:'purchase_update',
                extra: {
                    data: that.list,
                    type:that.type
                }
            })
        },
        choose_persons:function(){
            // ns.openWin('chooseperson_frm', '请选择', {
            //     source: 'transfer',
            // }); 
            ns.openWin('chooseuser_frm', '请选择', {
                source: 'transfer',
            });  
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.list = api.pageParam.list;
    app.type = api.pageParam.type;
    api.addEventListener({
        name:'purchase_add'
    }, function(ret){
        for (var i = 0; i < ret.value.data.length; i++) {
            var item = ret.value.data[i];
            app.list.push(item);
        }
        let obj = {};
        let peon = app.list.reduce((cur,next) => {
            obj[next.UserID] ? "" : obj[next.UserID] = true && cur.push(next);
            return cur;
        },[]) ;
        app.list=peon;
        console.log(JSON.stringify(app.list))
    })
    // api.addEventListener({
    //     name: 'purchase_add'
    // }, function (ret) {
    //     if( app.chooseType==1){
    //         var chooselist=ret.value.data;
    //         app.select_person(chooselist,1);
    //         // app.choose_id_list=ret.value.data;
    //     }
    //     if( app.chooseType==0){

    //         var select_list=ret.value.data;
    //         app.select_person(select_list,0);
    //     }

    // })

};
